package leetcode.L500;

import java.util.Arrays;
import java.util.Comparator;

public class EX435 {
    public static void main(String[] args) {
        int[][] intervals = {{0,2},{1,3},{2,4},{3,5},{4,6}};
        int res = 1;

        Arrays.sort(intervals, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if(o1[0]!=o2[0]){
                    return o1[0]-o2[0];
                }
                else{
                    return o1[1]-o2[1];
                }
            }

        });

        for(int i=0,j=1;i<intervals.length&&j<intervals.length;){
            if(intervals[i][1]<=intervals[j][0]){
                res++;
                i=j;
                j++;
            }
            else {
                j++;
            }
        }
        System.out.println(res);



    }
}
